package com.xuecheng.media.controller;

import com.xuecheng.api.media.MediaAuditApi;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.entity.Media;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
public class MediaAuditController implements MediaAuditApi {

    @Autowired
    private MediaService mediaService;

    /**
     * 分页查询媒资信息  -  及根据审核条件查询媒资信息
     *
     * @param params 分页查询参数
     * @param model  查询条件
     * @return PageVO
     */

    @PostMapping("m/media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {

        //获取结果对象并且返回
        PageVO<Media> pageVO = this.mediaService.queryMediaList(params, model, null);
        return pageVO;
    }


    /**
     * 媒资审核  === 运营平台
     *
     * @param vo 媒资审核时的VO对象
     */
    @PutMapping("m/media/audit")
    public void approve(@RequestBody MediaAuditVO vo) {
        //将vo转换为po实体类
        Media media = MediaConvert.INSTANCE.vo2entity(vo);
        //审核媒资
        this.mediaService.approve(media);
    }

    /**
     * 预览媒资 === 运营平台
     *
     * @param mediaId 媒资id
     * @return 播放地址
     */
    @GetMapping("m/media/preview/{mediaId}")
    public Object preview(@PathVariable Long mediaId) {
        Object preview = this.mediaService.preview(mediaId);
        return preview;
    }
}
